// #ifdef APP-PLUS
const univerifyManager = uni.getUniverifyManager();
// #endif 
export const univerifyLogin = {
	data() {
		return {
			canUniverifyLogin: false
		};
	},
	onLoad() {
		// #ifdef APP-PLUS
		let that = this;
		univerifyManager.preLogin({
			provider: 'univerify',
			success() {
				that.canUniverifyLogin = true;
				that.univerifyLogin();
			},
			fail(res) {
				console.info(res)
				that.canUniverifyLogin = false;
			}
		});
		// #endif 
	},
	methods: {
		univerifyLogin() {
			let that = this;
			univerifyManager.login({
				provider: 'univerify',
				univerifyStyle: {
					fullScreen: true,
					authButton: {
						normalColor: '#ffd946',
						highlightColor: '#ffee31',
						disabledColor: '#ffe865',
						textColor: '#ffffff'
					},
					icon: {
						path: 'static/logo.png'
					},
				},
				success(res) {
					// 登录成功
					// login(loginBody).then(res => {
					// 	if (res.code == 200) {
					// 		this.$tn.vuex('vuex_token', res.result.tokenValue);
					// 		this.$tn.vuex('vuex_login_flag', true);
					// 		uni.$tn.message.toast(res.msg);
					// 		getUserInfo().then(resUser => {
					// 			this.$tn.vuex('vuex_user', resUser.result);
					// 			this.$common.navigateTo('/pages/index');
					// 			return;
					// 		})
					// 	}

					// }).catch(err => {
					// 	console.log('云函数报错', err);
					// }).finally(res => {})

					// 在得到access_token后，通过callfunction调用云函数
					uniCloud.callFunction({
						name: 'getPhoneNumber',
						data: {
							'access_token': res.authResult.access_token,
							'openid': res.authResult.openid
						}
					}).then(res => {
						console.info(res);
					}).catch(err => {
						// 处理错误
					}).finally(res => {
						uni.closeAuthView();
					})
				},
				fail(res) {
					uni.closeAuthView();
				}
			});
		},
	},
};